package unitTests;

import static org.junit.Assert.*;

import org.junit.Test;

import bank.BankAccount;

public class BankAccountTest {

	@Test
	public void testRoutineDeposit()
	{
		BankAccount a = new BankAccount(1000,100);
		a.deposit(1);
		assertEquals(101, a.getBalance(), .01);
		assertEquals(2, a.numTransactions());
	}

	@Test
	public void testNegativeDeposit()
	{
		BankAccount a = new BankAccount(1000,100);
		a.deposit(-1);
		assertEquals(100, a.getBalance(), .01);
		assertEquals(1, a.numTransactions());
	}
	
	@Test
	public void testZeroDeposit()
	{
		BankAccount a = new BankAccount(1000,100);
		a.deposit(0);
		assertEquals(100, a.getBalance(), .01);
		assertEquals(1, a.numTransactions());
	}
	
	@Test
	public void testNegativeWithdrawal()
	{
		BankAccount a = new BankAccount(1000,100);
		a.withdraw(-1);
		assertEquals(100, a.getBalance(), .01);
		assertEquals(1, a.numTransactions());
	}
	
	@Test
	public void testZeroWithdrawal()
	{
		BankAccount a = new BankAccount(1000,100);
		a.withdraw(0);
		assertEquals(100, a.getBalance(), .01);
		assertEquals(1, a.numTransactions());
	}
	
	@Test
	public void testOverdraftProtection()
	{
		BankAccount a = new BankAccount(1000,100);
		a.withdraw(a.getBalance()+ 1);
		assertEquals(100, a.getBalance(), .01);
		assertEquals(1, a.numTransactions());
	}
	
	@Test
	public void testClosedAccountDeposit()
	{
		BankAccount a = new BankAccount(1000,100);
		a.close();
		a.deposit(1);
		assertEquals(0, a.getBalance(), .01);
		assertEquals(2, a.numTransactions());
	}
	
	@Test
	public void testClosedAccountWithdrawal()
	{
		BankAccount a = new BankAccount(1000,100);
		a.close();
		a.withdraw(1);
		assertEquals(0, a.getBalance(), .01);
		assertEquals(2, a.numTransactions());
	}
	
	@Test
	public void testSuspendedAccountDeposit()
	{
		BankAccount a = new BankAccount(1000,100);
		a.suspend();
		a.deposit(1);
		assertEquals(100, a.getBalance(), .01);
		assertEquals(1, a.numTransactions());
	}
	
	@Test
	public void testSuspendedAccountWithdrawal()
	{
		BankAccount a = new BankAccount(1000,100);
		a.suspend();
		a.withdraw(1);
		assertEquals(100, a.getBalance(), .01);
		assertEquals(1, a.numTransactions());
	}
	
	@Test
	public void testCorrectNumberOfTransactions()
	{
		BankAccount a = new BankAccount(1000,100);
		a.deposit(1);
		assertEquals(2, a.numTransactions());
		assertEquals("Open", a.getStatus());
	}
	
	@Test
	public void testInitialAccountState()
	{
		BankAccount a = new BankAccount(1000,100);
		assertEquals("Open", a.getStatus());
	}
	
	@Test
	public void testUnableToOpenClosedAccount()
	{
		BankAccount a = new BankAccount(1000,100);
		a.close();
		assertEquals("Closed", a.getStatus());
		a.open();
		assertEquals("Closed", a.getStatus());
	}
	
	@Test
	public void testAbleToOpenSuspendedAccount()
	{
		BankAccount a = new BankAccount(1000,100);
		a.suspend();
		assertEquals("Suspended", a.getStatus());
		a.open();
		assertEquals("Open", a.getStatus());
	}
	
	@Test
	public void testClosingAnOpenAccountSetsBalanceToZero()
	{
		BankAccount a = new BankAccount(1000,100);
		a.close();
		assertEquals("Closed", a.getStatus());
		assertEquals(2, a.numTransactions());
		assertEquals(0, a.getBalance(), .01);
	}
	
	@Test
	public void testClosingASuspendedAccountSetsBalanceToZero()
	{
		BankAccount a = new BankAccount(1000,100);
		a.suspend();
		a.close();
		assertEquals("Closed", a.getStatus());
		assertEquals(2, a.numTransactions());
		assertEquals(0, a.getBalance(), .01);
	}
}
